home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 42
/
Amiga Format AFCD42 (Issue 126, Aug 1999).iso
/
-serious-
/
programming
/
other
/
jikes
/
src
/
system.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1999-05-14
|
22KB
|
573 lines
// $Id: system.cpp,v 1.6 1999/02/12 14:39:13 shields Exp $
//
// This software is subject to the terms of the IBM Jikes Compiler
// License Agreement available at the following URL:
// http://www.ibm.com/research/jikes.
// Copyright (C) 1996, 1998, International Business Machines Corporation
// and others. All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
#include "config.h"
#include <sys/stat.h>
#include "control.h"
#include "semantic.h"
#include "zip.h"
int Control::ConvertUnicodeToUtf8(wchar_t *source, char *target)
{
int length = 0;
for (; *source; source++)
{
int ch = *source;
if (ch == 0)
{
target[length++] = (char) 0xC0;
target[length++] = (char) 0x80;
}
else if (ch <= 0x007F)
target[length++] = (char) ch;
else if (ch <= 0x07FF)
{
target[length++] = (char) ((char) 0xC0 | (char) ((ch >> 6) & 0x001F)); // bits 6-10
target[length++] = (char) ((char) 0x80 | (char) (ch & 0x003F)); // bits 0-5
}
else
{
target[length++] = (char) ((char) 0xE0 | (char) ((ch >> 12) & 0x000F));
target[length++] = (char) ((char) 0x80 | (char) ((ch >> 6) & 0x003F));
target[length++] = (char) ((char) 0x80 | (char) (ch & 0x3F));
}
}
target[length] = U_NULL;
return length;
}
void Control::FindPathsToDirectory(PackageSymbol *package)
{
if (package -> directory.Length() == 0)
{
PackageSymbol *owner_package = package -> owner;
if (owner_package) // package is a subpackage?
{
for (int i = 0; i < owner_package -> directory.Length(); i++)
{
DirectorySymbol *owner_directory_symbol = owner_package -> directory[i],
*subdirectory_symbol = owner_directory_symbol -> FindDirectorySymbol(package -> Identity());
if ((! subdirectory_symbol) && (! owner_directory_symbol -> IsZip()))
{
int length = owner_directory_symbol -> DirectoryNameLength() + package -> Utf8NameLength() + 1; // +1 for '/'
char *directory_name = new char[length + 1]; // +1 for '\0';
strcpy(directory_name, owner_directory_symbol -> DirectoryName());
if (owner_directory_symbol -> DirectoryName()[owner_directory_symbol -> DirectoryNameLength() - 1] != U_SLASH)
strcat(directory_name, StringConstant::U8S__SL_);
strcat(directory_name, package -> Utf8Name());
if (::SystemIsDirectory(directory_name))
subdirectory_symbol = owner_directory_symbol -> InsertAndReadDirectorySymbol(package -> Identity());
delete [] directory_name;
}
if (subdirectory_symbol)
package -> directory.Next() = subdirectory_symbol;
}
}
else
{
//
// Recall that since classpath[0] contains the default directory, we always
// start searching at location 1.
//
for (int k = 1; k < classpath.Length(); k++)
{
PathSymbol *path_symbol = classpath[k];
DirectorySymbol *directory_symbol = path_symbol -> RootDirectory() -> FindDirectorySymbol(package -> Identity());
if ((! directory_symbol) && (! path_symbol -> IsZip()))
{
int length = path_symbol -> Utf8NameLength() + package -> Utf8NameLength() + 1; // +1 for '/'
char *directory_name = new char[length + 1]; // +1 for '/' +1 for '\0'
strcpy(directory_name, path_symbol -> Utf8Name());
strcat(directory_name, StringConstant::U8S__SL_);
strcat(directory_name, package -> Utf8Name());
if (::SystemIsDirectory(directory_name))
directory_symbol = path_symbol -> RootDirectory() -> InsertAndReadDirectorySymbol(package -> Identity());
delete [] directory_name;
}
if (directory_symbol)
package -> directory.Next() = directory_symbol;
}
}
}
return;
}
void Control::ProcessGlobalNameSymbols()
{
this -> dot_name_symbol = FindOrInsertName(US__DO_, wcslen(US__DO_));
this -> dot_dot_name_symbol = FindOrInsertName(US__DO__DO_, wcslen(US__DO__DO_));
this -> length_name_symbol = FindOrInsertName(US_length, wcslen(US_length));
this -> init_name_symbol = FindOrInsertName(US__LT_init_GT_, wcslen(US__LT_init_GT_));
this -> clinit_name_symbol = FindOrInsertName(US__LT_clinit_GT_, wcslen(US__LT_clinit_GT_));
this -> block_init_name_symbol = FindOrInsertName(US_block_DOLLAR, wcslen(US_block_DOLLAR));
this -> this0_name_symbol = FindOrInsertName(US_this0, wcslen(US_this0));
this -> clone_name_symbol = FindOrInsertName(US_clone, wcslen(US_clone));
this -> object_name_symbol = FindOrInsertName(US_Object, wcslen(US_Object));
this -> type_name_symbol = FindOrInsertName(US_TYPE, wcslen(US_TYPE));
this -> class_name_symbol = FindOrInsertName(US__class_DOLLAR, wcslen(US__class_DOLLAR));
return;
}
//
// Create the unnamed package and set up global names.
//
void Control::ProcessUnnamedPackage()
{
unnamed_package = external_table.InsertPackageSymbol(FindOrInsertName(US_EMPTY, wcslen(US_EMPTY)), NULL);
//
// Create an entry for no_type. no_type is used primarily to signal an error
//
no_type = unnamed_package -> InsertSystemTypeSymbol(FindOrInsertName(US__QU__QU_, wcslen(US__QU__QU_)));
no_type -> SetSignature(Utf8_pool.FindOrInsert(U8S__DO_, strlen(U8S__DO_))); // give it some signature...
no_type -> outermost_type = no_type;
no_type -> SetOwner(unnamed_package);
no_type -> MarkBad();
//
// Create an entry for the null type.
//
null_type = unnamed_package -> InsertSystemTypeSymbol(FindOrInsertName(US_null, wcslen(US_null)));
null_type -> outermost_type = null_type;
null_type -> SetOwner(unnamed_package);
null_type -> SetACC_PUBLIC();
return;
}
void Control::ProcessPath()
{
NameSymbol *dot_path_name_symbol;
#if defined(UNIX_FILE_SYSTEM) || defined(AMIGAOS_FILE_SYSTEM)
dot_path_name_symbol = dot_name_symbol;
#elif defined(WIN32_FILE_SYSTEM) /*|| defined(AMIGAOS_FILE_SYSTEM)*/
char *main_current_directory = option.GetMainCurrentDirectory();
int dot_path_name_length = strlen(main_current_directory);
wchar_t *dot_path_name = new wchar_t[dot_path_name_length + 1];
for (int i = 0; i < dot_path_name_length; i++)
dot_path_name[i] = main_current_directory[i];
dot_path_name[dot_path_name_length] = U_NULL;
dot_path_name_symbol = FindOrInsertName(dot_path_name, dot_path_name_length);
delete [] dot_path_name;
#endif
//
// We need a place to start. Allocate a "." directory with no owner initially. (Hence, the null argument.)
// Allocate a "." path whose associated directory is the "." directory.
// Identify the "." path as the owner of the "." directory.
//
DirectorySymbol *dot_directory = new DirectorySymbol(dot_name_symbol, NULL);
classpath.Next() = classpath_table.InsertPathSymbol(dot_path_name_symbol, dot_directory);
dot_directory -> ResetDirectory(); // Note that main_root_directory is reset after it has been assigned an owner above
root_directories.Next() = dot_directory;
//
//
//
if (option.classpath)
{
int max_path_name_length = strlen(option.classpath) + 1; // The longest possible path name we can encounter
wchar_t *path_name = new wchar_t[max_path_name_length + 1]; // +1 for '\0'
wchar_t *input_name = NULL;
char *full_directory_name = NULL;
for (char *path = option.classpath, *path_tail = &path[strlen(path)]; path < path_tail; path++)
{
#ifdef WIN32_FILE_SYSTEM
delete []